/**  
 * All rights Reserved, Designed By Android_Robot   
 * @Title:  ZoneSearchNullFragment.java   
 * @Package com.jiyi.activity.zone   
 * @Description:    TODO(用一句话描述该文件做什么)   
 * @author: HYM     
 * @date:   2017-6-13 下午4:54:45   
 * @version V1.0     
 */
package com.jiyi.activity.zone;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.TextView;

import com.jiyi.event.ZoneSearchEvent;
import com.swift.maintenance.R;
import com.swift.widget.KeywordsFlow;

import org.greenrobot.eventbus.EventBus;

import java.util.Random;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @ClassName: ZoneSearchNullFragment
 * @Description:TODO(这里用一句话描述这个类的作用)
 * @author: HYM
 * @date: 2017-6-13 下午4:54:45
 * 
 */
public class ZoneSearchNullFragment extends Fragment implements OnClickListener{

	// @Bind(R.id.tvWXXFZ)
	// TextView tvWXXFZ;
	//
	// @Bind(R.id.tvJJXF)
	// TextView tvJJXF;

	public static final String[] keywords = { "微型消防站","家居消防","公益活动","智能家居","防火小知识","消防百科","吴思桥","涨知识","灭火器","逃生通道","消防车","水罐消防车","消防泵","干粉枪","标准喷头","消防供水","消防水池","泡沫溜槽","空气泡沫产生器","喷射强度" };

	@BindView(R.id.kf)
	KeywordsFlow kf;

	@SuppressLint("NewApi")
	@Override
	@Nullable
	public View onCreateView(LayoutInflater inflater,
			@Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.fragment_zone_search_null, null,
				false);
		ButterKnife.bind(this, view);
		// 测试ShapeDrawble用法
		// tvWXXFZ.setBackground(new ShapeDrawbleZG(tvWXXFZ, 7,
		// false).setEdgColor(Color.GREEN));
		// tvJJXF.setBackground(new ShapeDrawbleZG(tvJJXF, 7,
		// false).setEdgColor(Color.RED));
		kf.setDuration(800l);
		kf.setOnItemClickListener(this);
		kf.rubKeywords();
		// 添加
		feedKeywordsFlow(kf, keywords);
		kf.go2Show(KeywordsFlow.ANIMATION_IN);
		return view;
	}

	// @OnClick({ R.id.tvWXXFZ,R.id.tvJJXF})
	// public void onClick(View view) {
	// switch (view.getId()) {
	// case R.id.tvWXXFZ:
	// EventBus.getDefault().post(new
	// ZoneSearchEvent(tvWXXFZ.getText().toString()));
	// break;
	// case R.id.tvJJXF:
	// EventBus.getDefault().post(new
	// ZoneSearchEvent(tvJJXF.getText().toString()));
	// break;
	// default:
	// break;
	// }
	// }
	
	private static void feedKeywordsFlow(KeywordsFlow keywordsFlow, String[] arr) {
		Random random = new Random();
		for (int i = 0; i < KeywordsFlow.MAX; i++) {
			int ran = random.nextInt(arr.length);
			String tmp = arr[ran];
			keywordsFlow.feedKeyword(tmp);
		}
	}
	
	@Override
	public void onClick(View v) {
		if (v instanceof TextView) {
			String keyword = ((TextView) v).getText().toString();
			Log.e("Search", keyword);
			 EventBus.getDefault().post(new ZoneSearchEvent(keyword));
		}
	}
}
